package com.bw.zg3park2212.fg

import android.annotation.SuppressLint
import android.app.ActionBar
import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.PopupWindow
import android.widget.RadioButton
import androidx.recyclerview.widget.LinearLayoutManager
import com.bw.base.entity.GongAddParam
import com.bw.base.mvvm.BaseFram
import com.bw.zg3park2212.R
import com.bw.zg3park2212.adpter.GongAdpter
import com.bw.zg3park2212.databinding.FragmentBlank4Binding
import com.bw.zg3park2212.viewmodel.GongViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class BlankFragment4 : BaseFram<FragmentBlank4Binding,GongViewModel>() {
    lateinit var gongAdpter: GongAdpter
    var satues=""
    @SuppressLint("MissingInflatedId")
    override fun intitView() {
        gongAdpter= GongAdpter()
        binding.rv.adapter=gongAdpter
        binding.rv.layoutManager=LinearLayoutManager(context)
        viewmodel.getGong(4,10)
        binding.addPark.setOnClickListener {

            val popupWindow= PopupWindow(context)
            val inflate = LayoutInflater.from(context).inflate(R.layout.item_popgong_add, null)
            val btnYes = inflate.findViewById<Button>(R.id.btn_yes)
            val btnNo = inflate.findViewById<Button>(R.id.btn_no)
            val title = inflate.findViewById<EditText>(R.id.gong_add_title)
            val content = inflate.findViewById<EditText>(R.id.gong_add_content)
            val yiyuedu = inflate.findViewById<RadioButton>(R.id.gong_add_yiyuedu)
            val weiyuedu = inflate.findViewById<RadioButton>(R.id.gong_add_weiyuedu)
            btnYes.setOnClickListener {
                var gongAddParam=GongAddParam()
                gongAddParam.title=title.text.toString()
                gongAddParam.content=content.text.toString()
                yiyuedu.setOnClickListener {
                    satues="已阅读"
                }
                weiyuedu.setOnClickListener {
                    satues="未阅读"
                }
                gongAddParam.status="未阅读"
               viewmodel.getAddGong(gongAddParam)
            }
            btnNo.setOnClickListener {
                popupWindow.dismiss()
            }
            popupWindow.isFocusable=true
            popupWindow.isOutsideTouchable=true
            popupWindow.width= ActionBar.LayoutParams.MATCH_PARENT
            popupWindow.height=500
            popupWindow.contentView=inflate
            popupWindow.showAtLocation(binding.addPark, Gravity.BOTTOM,0,0)
        }
    }

    override fun intitData() {
        viewmodel.gongSuccse.observe(this){
            gongAdpter.data.clear()
            gongAdpter.addData(it)
            gongAdpter.notifyDataSetChanged()
        }
        viewmodel.gongAddSuccse.observe(this){
            gongAdpter.addData(it)
            gongAdpter.notifyDataSetChanged()
        }
    }


}